package com.socialrss.accounts;

import java.util.LinkedHashMap;

import com.socialrss.utils.SocialRssModel;

public class Group extends AbstractHolder{
	private LinkedHashMap<Integer, AbstractHolder> _subholders;
	private int _listSizeOnDb;
	public Group(int id, String name, int selected){
		super(id);
		super.setName(name);
		if(selected == 1)
			super.setTurnedOn(true);
		else
			super.setTurnedOn(false);
		_subholders = new LinkedHashMap<Integer, AbstractHolder>();
		_listSizeOnDb = 0;
	}
	@Override
	public boolean isGroup(){
		return true;
	}
	public boolean isMostOuter(){
		return (this.getParentId()==-1);
	}
	public int getNumberOfElements(){
		if(_listSizeOnDb == 0)
			_listSizeOnDb = SocialRssModel.Instance(null).getNumOfContentsInGroup(this.getId());
		return _listSizeOnDb;
	}
	public LinkedHashMap<Integer, AbstractHolder> getsubholders(){
		if(_subholders.isEmpty()){
			/*
			 * If it is empty, fetch relevant data from db and return it
			 */
			_subholders = SocialRssModel.Instance(null).getContentOfGroup(this.getId());
		}
		return _subholders;
	}
	/**
	 * To initialize with an empty hash map, give parameter as null
	 * @param tempList
	 */
	public void setSubHolders(LinkedHashMap<Integer, AbstractHolder> tempList){
		if(tempList == null){
			_subholders = new LinkedHashMap<Integer, AbstractHolder>();
			_listSizeOnDb = 0;
		}
		else{
			_subholders = tempList;
			_listSizeOnDb = tempList.size();
		}
	}

}
